package compiler;

import java.io.*;
import java.util.*;

import parser.*;
import lexer.*;
import generatedFiles.*;
import visitor.*;
import symbol.*;

public class Main {
        public static void main(String [] args) throws ParseException, IOException{        	    
        		String src = "src/testes/Factorial.txt";
        		String aux = "src/testes/Auxiliar.txt";
        		
                ArrayList<String> errors = new ArrayList<String>();
                ArrayList<String> lexicalErrorImages = new ArrayList<String>();               

                InputStream mjFile = new FileInputStream(src);              
                
                Lexer l = new Lexer(mjFile);    
                
                try{
                	l.lexicalAnalysis(errors, lexicalErrorImages);                  
                }catch(ParseException pe){
                	System.out.println("Errooooo");
                }
                               
            	FileManipulation.makeParseFile(src, aux, lexicalErrorImages);                
                InputStream mjFileAux = new FileInputStream(aux);
                
                if(!errors.isEmpty()){
                    for(int i = 0; i < errors.size(); i++){
                        System.out.println(errors.get(i));
                    }                       
                }          
                

                Parser p = new Parser(mjFileAux);   
                p.parsingAnalysis();
                
                TypeCheck tc = new TypeCheck(mjFileAux);
                tc.doTypeChecking(p.prog);
        }
}
